from collections import UserDict
import os
from tkinter import messagebox
import redis
from redis import StrictRedis
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
import UI
import func
from functools import partial
import Function

host = '127.0.0.1' #Redis默认主机和端口
port = '6379'

redis_conn = redis.Redis(host = host, port = port, db = 0, decode_responses = True)
    

def login(Userid,UserPassword):                        #登录
    Userid = ui.textEdit.toPlainText()
    UserPassword = ui.textEdit_2.toPlainText()
    TruePassword = redis_conn.get('admin')
    if Userid == 'admin' and TruePassword == UserPassword:
        messagebox.showinfo(title="提示",message="已登录")
        os.system("python Function.py")
        MainWindow.close()
        
    else:
        messagebox.showinfo(title="提示",message="用户名或密码错误。")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    MainWindow = QMainWindow()
    ui = UI.Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    ui.pushButton.clicked.connect(partial(login,ui))

    sys.exit(app.exec_())